<template>
  <div class="box">
    <van-sidebar v-model="active">
      <van-sidebar-item
        v-for="item in classList"
        :key="item.cat_id"
        :title="item.cat_name"
      />
    </van-sidebar>
    <div class="info">
      <div class="info-box">
        <div v-for="(item,index) in childrenList" :key="item.cat_id">
        <div class="title">{{ item.cat_name }}</div>
        <div class="class" >
          <div class="com" v-for="v in childrenList[index].children" :key="v.cat_id">
            <img
              :src="v.cat_icon"
              alt=""
            />
            <div>{{v.cat_name}}</div>
          </div>
        </div>
      </div>
      </div>
    </div>
  </div>
</template>

<script>
import { comClasslistAPI } from '@/api/class'
export default {
  name: 'MyClassify',
  data () {
    return {
      active: 0,
      classList: [],
      childrenList: []
    }
  },
  created () {
    this.getList()
  },
  methods: {
    async getList () {
      const res = await comClasslistAPI()
      this.classList = res.message
      this.childrenList = this.classList[0].children
    }
  },
  watch: {
    active: {
      handler (newObj, oldObj) {
        this.childrenList = this.classList[newObj].children
      }
    }
  }
}
</script>

<style lang="less" scoped>
.info-box{
  height: 78vh;
}
.box {
  padding: 100px 0 50px 0;
  width: 100vw;
  height: 78vh;
  overflow: auto;
  position: fixed;
  left: 0;
  top: 0;
  z-index: -100;
  display: flex;
}
.van-sidebar {
  overflow: auto;
  width: 25%;
  .van-sidebar-item {
    text-align: center;
    font-size: 12px;
    background-color: #f5f5f5;
  }
}
.info {
  // justify-content: center;
  position: fixed;
  left: 25%;
  background-color: #f5f5f5;
  flex: 1;
  overflow: auto;
  .title {
    height: 30px;
    text-align: center;
    line-height: 30px;
    font-weight: 700;
    font-size: 16px;
  }
  .class {
    display: flex;
    flex-wrap: wrap;
    .com {
      width: 33.33%;
      text-align: center;
     margin-bottom: 10px;
      img {
        height: 60px;
        width: 60px;
      }
      div {
        text-align: center;
        font-size: 12px;
      }
    }
  }
}
</style>
